package com.jule.miaozhuapc.dao.impl;

import org.springframework.stereotype.Repository;

import com.jule.miaozhuapc.dao.CheckTodayDao;
import com.jule.miaozhuapc.domain.WawaCheckToday;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

@Repository
public class CheckTodayDAOImpl  implements CheckTodayDao{

	private EntityManager em;
	@PersistenceContext
	public void setEm(EntityManager em) {
		this.em = em;
	}

	@Override
	public WawaCheckToday findByUserId(Long userId) {
		//FiXME
		String hql = "from WawaCheckToday where userId = ? and isDelete = 0";
		List<WawaCheckToday> wawaCheckTodays = em.createQuery(hql, WawaCheckToday.class)
				.setParameter(1, userId)
				.getResultList();

		if(wawaCheckTodays != null && wawaCheckTodays.size() > 0){
			return wawaCheckTodays.get(0);
		}
		return null;
	}

}
